package com.zookeeper.basic.one;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * Created by 58 on 2016-7-15.
 */
public class ZkConstructSample implements Watcher {
    private static CountDownLatch countDownLatch = new CountDownLatch(1);

    public void process(WatchedEvent watchedEvent) {
        System.out.printf("--------------------------");
        if(Event.KeeperState.SyncConnected == watchedEvent.getState()){
            countDownLatch.countDown();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        try {
            ZooKeeper zooKeeper = new ZooKeeper("127.0.0.1:2181",5000,new ZkConstructSample());

        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("zookeeper session established....");
        countDownLatch.await();
    }
}
